// tnxcore-app.js

import util from './tnxcore-util';
import rpc from './tnxcore-app-rpc';

const app = {
    context: '',
    global: {},
    rpc: rpc,
    page: {},
    buildCsrfField(form) {
        const meta = document.querySelector('meta[name="csrf"]');
        if (meta) {
            const name = meta.getAttribute('parameter');
            const value = meta.getAttribute('content');
            if (name && value) {
                const input = document.createElement('input');
                input.type = 'hidden';
                input.name = name;
                input.value = value;
                form.appendChild(input);
            }
        }
    },
    logout() {
        if (util.build.isProduction()) {
            window.location.href = this.context + this.rpc.logoutProcessUrl;
            return Promise.resolve();
        } else {
            return this.rpc.logout();
        }
    },
};

export default app;
